//
//  WSFavourTableViewCell.m
//  GroupFourFM
//
//  Created by 王鑫 on 15/12/23.
//  Copyright © 2015年 GroupFour. All rights reserved.
//

#import "WSFavourTableViewCell.h"

@implementation WSFavourTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews
{

    self.newsPic = [[UIImageView alloc] init];
    self.newsPic.backgroundColor = CLEAR;
    [self.contentView addSubview:self.newsPic];
    [self.newsPic mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(@10);
        make.top.mas_equalTo(@10);
        make.width.equalTo(self.contentView.mas_height).offset(-20);
        make.bottom.mas_equalTo(@-10);
    }];
    
    self.newsTitle = [[WSBaseTitleLabel alloc] init];
    self.newsTitle.backgroundColor = CLEAR;
    self.newsTitle.font = [UIFont systemFontOfSize:18];
    [self.contentView addSubview:self.newsTitle];
    [self.newsTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.newsPic.mas_right).offset(10);
        make.top.equalTo(self.newsPic);
        make.right.mas_equalTo(@-40);
        make.height.equalTo(self.newsPic).multipliedBy(0.3);
    }];
    
    self.newsDigest = [[UILabel alloc] init];
    self.newsDigest.backgroundColor = CLEAR;
    self.newsDigest.font = [UIFont systemFontOfSize:13 weight:0];
    self.newsDigest.textColor = [UIColor lightGrayColor];
    self.newsDigest.numberOfLines = 2;
    [self.contentView addSubview:self.newsDigest];
    [self.newsDigest mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.newsPic.mas_right).offset(10);
        make.top.equalTo(self.newsTitle.mas_bottom);
        make.right.mas_equalTo(@-40);
        make.height.equalTo(self.newsPic).multipliedBy(0.4);
    }];
    
    UIImageView *iconImage = [[UIImageView alloc] init];
    iconImage.backgroundColor = CLEAR;
    iconImage.image = [UIImage imageNamed:@"album_tracks"];
    [self.contentView addSubview:iconImage];
    [iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.newsPic.mas_right).offset(10);
        make.bottom.equalTo(self.newsPic);
        make.width.equalTo(self.newsPic).multipliedBy(0.2);
        make.height.equalTo(self.newsPic).multipliedBy(0.2);
    }];
    
    self.nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    //    self.nextBtn.frame = CGRectMake(SCREEN_WIDTH-40, self.newsPic.frame.origin.y + self.newsPic.frame.size.height/2-15, 30, 30);
    self.nextBtn.backgroundColor = CLEAR;
    [self.contentView addSubview:self.nextBtn];
    [self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@(SCREEN_WIDTH-40));
        make.top.mas_equalTo(self.contentView).offset(45);
        make.width.mas_equalTo(@30);
        make.height.mas_equalTo(@30);
        
    }];
    
    self.contentCount = [[UILabel alloc] init];
    self.contentCount.backgroundColor = CLEAR;
    self.contentCount.font = [UIFont systemFontOfSize:13 weight:0];
    [self.contentView addSubview:self.contentCount];
    self.contentCount.textAlignment = NSTextAlignmentLeft;
    self.contentCount.textColor = [UIColor lightGrayColor];
    [self.contentCount mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(iconImage.mas_right).offset(2);
        make.bottom.equalTo(iconImage);
        make.right.mas_equalTo(@-40);
        make.height.equalTo(self.newsPic).multipliedBy(0.2);
    }];
    

    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.newsPic.mas_right).offset(SCREEN_HEIGHT*0.01);
        make.top.mas_equalTo(self.newsPic.mas_bottom).offset(9);
        make.right.mas_equalTo(self.contentView).offset(-SCREEN_HEIGHT*0.01);
        make.height.mas_equalTo(@0.5);
        
    }];
}

-(void)setModel:(WSFavourModel *)model
{
    [self.newsPic sd_setImageWithURL:[NSURL URLWithString:model.coverMiddle] placeholderImage:PLACEHOLDER_CELL_SAME];
    self.newsTitle.text = model.title;
    self.newsDigest.text = model.intro;
    self.contentCount.text = [NSString stringWithFormat:@"%@集", model.tracks];
    [self.contentCount sizeToFit];
}

@end
